//
//  BAIndexCollectionView.m
//  YunFu
//
//  Created by Bager on 2018/9/3.
//  Copyright © 2018年 yunfu. All rights reserved.
//

#import "BAIndexCollectionView.h"

#import "IndexFiveItemSizeCell.h"
#import "BAMainListVC.h"

@implementation BAIndexCollectionView

- (instancetype)init
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 设置每个item的大小，
    flowLayout.itemSize = CGSizeMake((kScreenWidth - kPublicMargin * 2) / 5.0, (kScreenWidth - kPublicMargin * 2) / 5.0 + 20);
    // 设置列的最小间距
    flowLayout.minimumInteritemSpacing = 0;
    // 设置最小行间距
    flowLayout.minimumLineSpacing = 0;
    // 设置布局的内边距
    flowLayout.sectionInset = UIEdgeInsetsMake(0, kPublicMargin, 0, kPublicMargin);
    // 滚动方向
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self = [super initWithFrame:CGRectMake(0, 0, kScreenWidth, ((kScreenWidth - kPublicMargin * 2) / 5.0 + 20) * 2)  collectionViewLayout:flowLayout];
    
    self.backgroundColor = [UIColor whiteColor];
    
    if (self)
    {
        self.dataSource = self;
        
        self.delegate = self;
        
        [self registerClass:[IndexFiveItemSizeCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
    }
    
    return self;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
}

- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    IndexFiveItemSizeCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
    
    NSArray *imgArray = @[@"yf2-mddh1",@"yf2-mddh2",@"yf2-mddh3",@"yf2-mddh4",@"yf2-mddh5",@"yf2-mddh6",@"yf2-mddh7",@"yf2-mddh8",@"yf2-mddh9",@"yf2-mddh10"];
    [cell.img setImage:[UIImage imageNamed:imgArray[indexPath.item]]];
    NSArray *titleArray = @[@"美食", @"购物", @"休闲娱乐", @"KTV", @"酒店", @"运动健身", @"丽人/美发", @"电影", @"周边游", @"家居装修"];
    cell.name.text = titleArray[indexPath.item];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    ZTNavigationViewController *nav = (ZTNavigationViewController *)[Tools sh_viewControllerWith:self].navigationController;
    BAMainListVC *list = [BAMainListVC new];
//    list.jz_navigationBarHidden = NO;
    [nav pushViewController:list animated:YES];
}

@end
